package com.eling.elcms.nursing.service.impl;

import com.eling.elcms.checkin.model.SignUpService;
import com.eling.elcms.checkin.service.IParameterBusinessService;
import com.eling.elcms.core.service.impl.GenericManagerImpl;
import com.eling.elcms.nursing.dao.ISignUpServContrDao;
import com.eling.elcms.nursing.model.SignUpServContr;
import com.eling.elcms.nursing.service.ISignUpServContrService;
import com.eling.elcms.travel.model.TravelContract;
import com.eling.elcms.travel.service.ITravelContractManager;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SignUpServContrServiceImpl extends GenericManagerImpl<SignUpServContr, Long>
		implements ISignUpServContrService, IParameterBusinessService {

	private static final Logger log = LoggerFactory.getLogger(SignUpServContrServiceImpl.class);

	ISignUpServContrDao signUpServContrDao;

	@Autowired
	private ITravelContractManager travelContractManager;

	@Autowired
	public void setDao(ISignUpServContrDao dao) {
		this.dao = dao;
		this.signUpServContrDao = dao;
	}

	/**
	 * 入住签约绑定权证
	 */
	@Override
	public void serviceBindContract(SignUpService signUpService, Long pkTravelContract) {
		TravelContract tc = travelContractManager.get(pkTravelContract);
		SignUpServContr susContr = new SignUpServContr();
		susContr.setSignUpService(signUpService);
		List<SignUpServContr> susContrList = query(susContr);
		if (!CollectionUtils.isEmpty(susContrList)) {
			susContr = susContrList.get(0);
		}
		susContr.setTravelContract(tc);
		save(susContr);
		log.info("会员：" + signUpService.getSignUp().getMember().getPersonalInfo().getName() + "-绑定会员证号-"
				+ tc.getMemberCertificates());
	}

	@Override
	public Map<String, Double> calculateDeduction(SignUpService signUpSvc, Date startDate, Date endDate) {
		// TODO Auto-generated method stub
		return  new HashMap<String, Double>();
	}

	@Override
	public Map<String, Double> getBasePrice() {
		// TODO Auto-generated method stub
		return new HashMap<String, Double>();
	}

	/*@Override
	public Map<String, Double> calculateDeduction(SignUpService signUpSvc, Date endDate) {
		Map<String, Double> map = new HashMap<>();
		SignUpServContr susContr = new SignUpServContr();
		susContr.setSignUpService(signUpSvc);
		List<SignUpServContr> susContrList = query(susContr);
		if (!CollectionUtils.isEmpty(susContrList)) {
			susContr = susContrList.get(0);
			// 会员证抵扣
			SettlementsRule ruleOne = travelContractManager.getContractSetlRuleByType(susContr.getTravelContract(),
					RuleType.Expense);
			if (ruleOne != null) {
				// 获取对应的规则实现类
				ISettlementsRule ruleImpl = ServiceLocator.getService(ruleOne.getServiceImpl());
				// 返回合同对应规则的本次抵扣、消费卷、其他的金额
				map.put(RuleType.Expense.name(), ruleImpl.calculate(null, susContr.getTravelContract(), signUpSvc.getCheckInDate(), endDate).getMoney());
			}
			// 床位费抵扣
			SettlementsRule ruleTwo = travelContractManager.getContractSetlRuleByType(susContr.getTravelContract(),
					RuleType.BedSubsidy);
			if (ruleOne != null) {
				// 获取对应的规则实现类
				ISettlementsRule ruleImpl = ServiceLocator.getService(ruleTwo.getServiceImpl());
				// 返回合同对应规则的本次抵扣、消费卷、其他的金额
				map.put(RuleType.BedSubsidy.name(), ruleImpl.calculate(null, susContr.getTravelContract(), signUpSvc.getCheckInDate(), endDate).getMoney());
			}
			// 福利积分抵扣
			SettlementsRule ruleThree = travelContractManager.getContractSetlRuleByType(susContr.getTravelContract(),
					RuleType.Coupon);
			if (ruleOne != null) {
				// 获取对应的规则实现类
				ISettlementsRule ruleImpl = ServiceLocator.getService(ruleThree.getServiceImpl());
				// 返回合同对应规则的本次抵扣、消费卷、其他的金额
				map.put(RuleType.Coupon.name(), ruleImpl.calculate(null, susContr.getTravelContract(), signUpSvc.getCheckInDate(), endDate).getMoney());
			}
		}
		return map;
	}*/

}
